home *** CD-ROM | disk | FTP | other *** search
/ Stolen Data 3 / Stolen Data 3.adf / SOURCE / Scroller1.s < prev    next >
Text File  |  1988-12-31  |  12KB  |  348 lines

  1. *****************************************************************************
  2. ;                         STOLEN DATA Issue #3
  3. ;                         ~~~~~~~~~~~~~~~~~~~~
  4. ;   Double buffered one bitplane scroller
  5. ;
  6. ;   Copyright ANARCHY 1990
  7. ;
  8. ;   Written on 3.6.90 by Kreator of ANARCHY
  9. ;
  10. ; This type of scroller is very efficient speedwise, but causes a number of
  11. ; problems, for instance it is difficult to implement variable speeds because
  12. ; the charcters are read a long time before they actually appear on screen.
  13. ; However even very large scrollers can be run in a very small amount of
  14. ; raster time using this technique.
  15. ;
  16. ;  General notes - At all times (unless specified) a6 points to the custom
  17. ; chip registers ($dff000) and a5 points to the list of variables.This allows
  18. ; indirect addressing modes to be used, which are much faster than absolute
  19. ; addressing and consume less memory. If these registers are needed in the
  20. ; course of a routine simply stick them on the stack, and pop them back off
  21. ; later.
  22. ; Scroller2 is very similar to this one but the scroll routine is not fully
  23. ; commented, but uses a technique commonly employed recently to get a base-
  24. ; relief 2 bitplane font from a single bitplane font. You'll have to figure
  25. ; it out for yourself, but its not difficult.
  26. *****************************************************************************
  27.  
  28.     Incdir    DF1:
  29.     Include    Source/NewCustomReg    ; Custom register label equates
  30.     Section    Scroller,Code_c        ; Assemble into chip mem if > ½ meg
  31.  
  32. TEST        = 1        ; Set this if you are only testing the menu
  33.                 ; as it will then return to DEVPAC
  34.  
  35. Trap_vec0    = $80
  36. Execbase    = $4
  37. Oldopen        = -$198
  38.  
  39.     Move.l    #Start,$80.w    ; Trap vector 0
  40.     Trap    #0        ; Execute trap 0 to give full control of the
  41.     Rts            ; 68000, needs an RTE to return.
  42.  
  43. Start
  44.     Bsr    Killsys        ; Disable the operating system
  45.     Bsr    Setup        ; Setup the demo
  46.     Bsr    Main        ; Now run the main demo routines
  47.     Bsr    Sysreturn    ; Return the system to its original state
  48.     Moveq.l    #0,d0        ; No errors !! A number of people neglect to
  49.                 ; do this, and that causes batch files (such
  50.                 ; as the startup sequence) to bomb out.
  51.     Rte        ; Return from exception ie. to the instruction after
  52.             ; the TRAP #0 call.
  53.  
  54. *****************************************************************************
  55. ;Killsys - Disable operating system and interrupts
  56. *****************************************************************************
  57. Killsys
  58.     Move.l    $4.w,a6        ; Execbase vector
  59.     Lea    Gfxname(pc),a1    ; Pointer to "graphics.library" into a1
  60.     Jsr    Oldopen(a6)    ; Open this library
  61.     Lea    Variables,a5    ; Get a pointer to the variable space
  62.     Lea    $dff000,a6    ; Pointer to custom chips
  63.     Move.l    d0,a0        ; Address of the graphics library
  64.     Move.l    38(a0),Sys_copl(a5)    ; Remember the System copperlist
  65.     Move    Intenar(a6),Int_set(a5)    ; System interrupts
  66.     Move    #$7fff,Intena(a6)    ; Now switch off all interrupts
  67.     Move.l    $6c.w,Vbl_vec(a5)    ; System vertical blanking int.
  68.     Move    Dmaconr(a6),Dma_set(a5)    ; System DMA
  69.     Move    #$7fff,Dmacon(a6)    ; Clear all DMA
  70.     Move    #$87c0,Dmacon(a6)    ; Now set the required DMA channels
  71.     Rts
  72.  
  73. Gfxname        Dc.b "graphics.library",0
  74.     Even
  75. *****************************************************************************
  76. ;Sysreturn - Re-enable operating system and interrupts
  77. *****************************************************************************
  78. Sysreturn
  79.     Move    #$7fff,Intena(a6)    ; Clear all interrupts
  80.     Move.l    Vbl_vec(a5),$6c.w    ; Restore VBL interrupt
  81.     Move    Int_set(a5),d0
  82.     Or    #$c000,d0
  83.     Move    d0,Intena(a6)        ; Restore system interrupts
  84.     Move    #$7fff,Dmacon(a6)
  85.     Move    Dma_set(a5),d0
  86.     Or    #$8200,d0
  87.     Move    d0,Dmacon(a6)        ; Restore system DMA
  88.     Move.l    Sys_copl(a5),Cop1lch(a6)    ; Restore system copperlist
  89.     Clr    Copjmp1(a6)
  90.     Rts
  91. *****************************************************************************
  92. ;Setup - Setup the menu system
  93. *****************************************************************************
  94. Setup
  95.  
  96. ;-- Remove the sprite data (prevents sprite streaks down the screen)
  97.  
  98.     Lea    Spr0data(a6),a0
  99.     Moveq    #7,d0
  100. Clop
  101.     Clr.l    (a0)
  102.     Addq.l    #8,a0
  103.     Dbf    d0,Clop
  104.  
  105. ;-- Clear the scroll area
  106.  
  107.     Lea    Screen1,a0
  108.     Move    #$bff,d0
  109. Clear_scroll
  110.     Clr.l    (a0)+
  111.     Dbf    d0,Clear_scroll
  112.  
  113. ;-- Initialise some variables
  114.  
  115.     Move.l    #Screen1,Current_bank(a5)    ; The two double buffered
  116.     Move.l    #Screen2,Other_bank(a5)        ; scroll areas
  117.     Move.l    #Scrolltext,Text_pt(a5)    ; Initialise the scrolltext
  118.     Move    #5,Speed(a5)        ; Set the scroll speed
  119.     Move.l    #Clstart,Cop1lch(a6)    ; Init. our own copperlist
  120.     Clr    Copjmp1(a6)
  121.     Rts
  122.  
  123. *****************************************************************************
  124. ; Main - Central demo calling routine + mouse button check
  125. *****************************************************************************
  126. Main
  127.     Move.l    Vposr(a6),d0
  128.     And.l    #$1ff00,d0
  129.     Cmp.l    #$00100,d0    ; Wait for vertical position 1
  130.     Bne.s    Main
  131.  
  132.     Bsr    Scroller    ; Jump to the scroll routine
  133.  
  134.     Move    #$200,d0    ; Small delay loop, this is needed because
  135. .Loop                 ; in general the scroll routine uses less
  136.     Dbf    d0,.Loop    ; than 1 raster line.As soon as more routines
  137.                 ; are added this is no longer required.
  138.  
  139.     Btst    #6,$bfe001    ; Check the left mouse button
  140.     Bne.s    Main
  141.  
  142.     Rts
  143. *****************************************************************************
  144. ; Scroller - The scroller is 80 bytes across of which only 46 are displayed
  145. ; at any one time. While one is displayed the other is updated, the last 48
  146. ; bytes (ie. 24 charcters) of the displayed scroller are copied into the
  147. ; first 48 bytes of the other. Then the remaining 32 bytes (16 characters)
  148. ; are plotted, from the scrolltext. Every frame two af these characters are
  149. ; copied, so it takes 20 frames to create the new scroll bank, and the banks
  150. ; are switched when the scroll pointer exceeds 256 (this pointer is just a
  151. ; pixel offset from the start of the displayed scroller) This means that the
  152. ; Maximum speed of the scroller is about 256/20 = 12 pixels per frame.
  153. ; Scroll_pt - the aforementioned scroll pointer
  154. ; Mode - Indicates if we need to copy the old data, or create new data from
  155. ;     the scrolltext. <12 means copy old data =>12&<20 means use the
  156. ;     scrolltext =20 means finished updating the scroller.
  157. *****************************************************************************
  158. Scroller
  159.     Move    Scroll_pt(a5),d0
  160.     Add    Speed(a5),d0
  161.     Cmp    #256,d0            ; Do we need a bank change
  162.     Blt.s    No_bank_change
  163.  
  164.     Move.l    Current_bank(a5),a0        ; Swap the display and update
  165.     Move.l    Other_bank(a5),Current_bank(a5)    ; scroll banks
  166.     Move.l    a0,Other_bank(a5)
  167.     Sub    #256,d0            ; Reset the scroll pointer
  168.     Clr    Mode(a5)
  169.  
  170. No_bank_change
  171.     Move    d0,Scroll_pt(a5)
  172.     Move    d0,d1    ; Remember d0 for calculating the shift register
  173.     Lsr    #4,d0    ; Convert d0 into a byte pointer on a word boundary
  174.     Add    d0,d0
  175.     Add    Current_bank+2(a5),d0    ; Add the current 
  176.     Move    d0,Scroll_planes+2    ; Stick it into the bitplane pointers
  177.     And    #$0f,d1    ; Only first four bits needed for shift register
  178.     Eor    #$0f,d1 ; Its a right shift so invert the bits as we are 
  179.             ; scrolling left
  180.     Move    d1,Scroll+2    ; Put it into the BPLCON1 register
  181.  
  182.     Cmp    #20,Mode(a5)
  183.     Beq    No_blitting    ; The update screen is ready
  184.     Cmp    #12,Mode(a5)
  185.     Blt    Char_scroll    ; Move the old characters
  186. New_chars
  187.     Moveq    #0,d0
  188.     Move    Mode(a5),d2
  189.     Lsl    #2,d2        ; Multiply mode by four ( 48-76 )
  190.     Move.l    Other_bank(a5),a2
  191.     Lea    (a2,d2),a2    ; Add mode*4 to the update screen pointer
  192.     Bsr    Read_char    ; Read the next character and plot it
  193.     Addq.l    #2,a2        ; Point to the next screen character position
  194.     Bsr    Read_char    ; Then read another character and plot it
  195.     Bra    Blit_exit    ; Thats it for now.
  196.  
  197. Read_char
  198.     Move.l    Text_pt(a5),a0    ; Scrolltext pointer
  199. New_char
  200.     Move.b    (a0)+,d0
  201.     Bne.s    Not_a_null    ; If 0 then reset the scrolltext pointer
  202.     Move.l    #Scrolltext,a0
  203.     Bra.s    New_char    ; Read the first character
  204. Not_a_null
  205.     Cmp    #$20,d0        ; Less than 32, then consider as a space
  206.     Bge.s    Not_control
  207.     Moveq    #$20,d0
  208. Not_control
  209.     Cmp    #$5b,d0        ; Convert lowercase to uppercase
  210.     Blt.s    Not_lower_case
  211.     Sub    #$20,d0
  212. Not_lower_case
  213.     Move.l    a0,Text_pt(a5)    ; Save the new scrolltext pointer
  214.     Sub    #$20,d0
  215.     Add    d0,d0        ; Convert ascii into a word pointer
  216.     Lea    Charpos(pc),a0    ; Table of character positions
  217.     Move    (a0,d0),d1
  218.     Lea    Font(pc),a1
  219.     Lea    (a1,d1),a1    ; a1 now points to the required character
  220.                 ; graphic image.
  221.  
  222.     Move.l    #-1,Bltafwm(a6)
  223.     Move.l    a2,Bltdpth(a6)
  224.     Move.l    a1,Bltapth(a6)
  225.     Move.l    #$09f00000,Bltcon0(a6)    ; Just a direct copy from A to D
  226.     Move.l    #$0026004e,Bltamod(a6)    ; Screen is $50 wide, font is $28 wide
  227.     Move    #(16<<6)!1,Bltsize(a6)    ; 16 pixels deep
  228.     Bra    Blit_wait        ; Wait for the blitter to finish
  229.  
  230.  
  231. Char_scroll
  232.     Move    Mode(a5),d0
  233.     Lsl    #2,d0
  234.     Move.l    Other_bank(a5),a0
  235.     Move.l    Current_bank(a5),a1
  236.     Lea    (a0,d0),a0
  237.     Lea    32(a1,d0),a1
  238.     
  239.     Move.l    #-1,Bltafwm(a6)
  240.     Move.l    a0,Bltdpth(a6)
  241.     Move.l    a1,Bltapth(a6)
  242.     Move.l    #$09f00000,Bltcon0(a6)
  243.     Move.l    #$004c004c,Bltamod(a6)
  244.     Move    #64*16+2,Bltsize(a6)    ; Copy two whole characters at once
  245.     Bsr    Blit_wait
  246. Blit_exit
  247.     Addq    #1,Mode(a5)    ; Move the mode on one
  248. No_blitting
  249.     Rts
  250.  
  251.  
  252. Blit_wait
  253.     Btst    #14,Dmaconr(a6)    ; Is the blitter still at work?
  254.     Bne.s    Blit_wait    ; Yes, well carry on waiting then.
  255.     Rts
  256. *****************************************************************************
  257. ;   Copperlist1 for the menu selector screen
  258. ; For those readers unfamiliar with my coding, I generally use macros for
  259. ; generating my copperlists. These I find to be easier to debug etc. but do
  260. ; take a little longer to assemble, obviously though for much larger
  261. ; copperlists (such as the background effect on the menu-loader) a generating
  262. ; routine should be employed.
  263. *****************************************************************************
  264. Clstart
  265.     Wait    0,20        ; Give the processor time to update the cl.
  266.     Mov    $9a64,Diwstrt
  267.     Mov    $aad1,Diwstop
  268.     Mov    $0028,Ddfstrt    ; Horizontal scrolling overscan screen
  269.     Mov    $00d8,Ddfstop    ; ie. 368 pixels wide
  270.     
  271.     Mov    0,Color00
  272.     Mov    $666,Color01
  273.     Mov    $fff,Color02
  274.     Mov    $aaa,Color03
  275.     Mov    34,Bpl1mod    ; Scroller is actually 80 bytes wide
  276. Scroll
  277.     Mov    0,Bplcon1
  278.     Mov    0,Bplcon2
  279. Scroll_planes
  280.     Mov    $00,Bpl1ptl
  281.     Mov    7,Bpl1pth
  282.     Mov    $1200,Bplcon0    ; Single bitplane
  283.     Wait    $fe,$ff
  284.  
  285. *****************************************************************************
  286. ; Binaries
  287. *****************************************************************************
  288. Font
  289.     Incbin    Binary/Bubble.font    ; This font was drawn by KREATOR
  290.                     ; so credit me if you use it
  291.  
  292. ; The following table is used to calculate a pointer to the required
  293. ; character and in general must be created by hand. Some coders advocate a
  294. ; different approach, which is to have all your characters stacked on top
  295. ; of each other and then the pointers are very easy to calculate with a
  296. ; multiply. I still prefer this method myself.
  297.  
  298. Charpos    Dc.w    $0000,$0002,$0004,$0006,$0008,$000a,$000c,$000e ; !"#$%&'
  299.     Dc.w    $0010,$0012,$0014,$0016,$0018,$001a,$001c,$001e ;()*+,-./
  300.     Dc.w    $0020,$0022,$0024,$0026,$0280,$0282,$0284,$0286 ;01234567
  301.     Dc.w    $0288,$028a,$028c,$028e,$0290,$0292,$0294,$0296 ;89:;<=>?
  302.     Dc.w    $0298,$029a,$029c,$029e,$02a0,$02a2,$02a4,$02a6 ;@ADCDEFG
  303.     Dc.w    $0500,$0502,$0504,$0506,$0508,$050a,$050c,$050e ;HIJKLMNO
  304.     Dc.w    $0510,$0512,$0514,$0516,$0518,$051a,$051c,$051e ;PQRSTUVW
  305.     Dc.w    $0520,$0522,$0524,$0526                         ;XYZ[\]^_
  306.  
  307. ; Zero terminated scrolltext, allows a mixture of upper and lower case
  308. ; although all the text will be displayed in uppercase. Also you can edit
  309. ; the text in any text editor, as the scroller counts all control characters
  310. ; such as 10 (line feed) as spaces.
  311.  
  312. Scrolltext
  313.     Dc.b    "insert your own scrolltext here !!!"
  314.     Dc.b    "     this scroller was written for "
  315.     Dc.b    "STOLEN DATA, copyright ANARCHY 1990"
  316.     Dc.b    "                                   ",0
  317.     Even
  318.  
  319. *****************************************************************************
  320. ;   Variables
  321. *****************************************************************************
  322.  
  323.     Rsreset
  324. Int_set        Rs.w 1    ; System interrupts
  325. Dma_set        Rs.w 1    ; System DMA channels
  326. Sys_copl    Rs.l 1    ;  ""    copperlist
  327. Vbl_vec        Rs.l 1    ;  ""    vertical blanking interrupt
  328. Scroll_pt    Rs.w 1    ; Scroll pointer, offset in pixels
  329. Mode        Rs.w 1    ; <12 COPY OLD, >=12 <20 NEW CHARS, =20 STOP
  330. Current_bank    Rs.l 1    ; Currently displayed scroller
  331. Other_bank    Rs.l 1    ; The update scroller
  332. Text_pt        Rs.l 1    ; Pointer to the scrolltext
  333. Speed        Rs.w 1    ; Scroll speed (must be less than 12)
  334.  
  335. Varisize    Rs.b 0    ; Simply used to determine how much space is needed
  336.             ; for the variable list
  337.  
  338. Variables    Dcb.b Varisize    ; Reserve space for the variables
  339.  
  340. ;-- Reserve some space for screens etc..
  341.  
  342.     Rsset $70000
  343. Screen1        Rs.b    16*80
  344. Screen2        Rs.b    16*80
  345.  
  346.  
  347.  
  348.